/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package drt;

import evaluation.Graph;
import java.util.LinkedHashSet;
import java.util.Map;
import logic.Type;

/**
 *
 * @author phong
 */
public class DrtCardinality implements DrtEntity {
    
    DrtEntity arg;
    
    public DrtCardinality(DrtEntity arg) {
        this.arg = arg;
    }
    
    public DrtEntity getArg() {
        return this.arg;
    }
    
    @Override
    public Type getType() {
        return Type.ENTITY_TYPE;
    }
    
    @Override
    public void setType(Type t) {}
    
    @Override
    public void setName(String name) {}
    
    @Override
    public String getName() {
        return "card";
    }
    
    @Override
    public void getAllVariables(LinkedHashSet<DrtVariable> vars) {
        if (this.arg instanceof DrtVariable)
            vars.add((DrtVariable)this.arg);
    }

    @Override
    public void getRefs(LinkedHashSet<DRSReferent> refs) {
        if (this.arg instanceof DRSReferent)
            refs.add((DRSReferent)this.arg);
    }
    
    @Override
    public DrtCardinality simplify() {
        return this;
    }
    
    @Override
    public DrtCardinality replace(DrtVariable var, DrtExpression exp) {
        if (this.arg.equals(var)) {
            if (exp instanceof DrtEntity)
                return new DrtCardinality((DrtEntity)exp);
            else if (exp instanceof DrtVariable)
                return new DrtCardinality(new DrtEntityVariable(((DrtVariable)exp).getName()));
            else 
                throw new Error("incorrect object");
        }
        else 
            return this;
    }
    
    @Override
    public boolean equals(Object other) {
        if (other instanceof DrtCardinality)
            return this.arg.equals(((DrtCardinality)other).arg);
        else 
            return false;
    }
    
    @Override
    public int hashCode() {
        return "cardinality".hashCode();
    }
    
    @Override
    public String toString() {
        return "card(" + this.arg.toString() + ")";
    }
    
    @Override
    public Graph toGraph() {
        return new Graph();        
    }
    
    @Override
    public DrtCardinality getTemplate(Map<String,String> map) {
        return this;
    }
}
